﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChainOfResponsibilityPattern;

internal abstract class AbstractAuditer
{
    public required string Name { get; set; }

    public required int AuditHours { get; set; }

    public abstract void Audit(ApplyContext context);
    private AbstractAuditer auditer;
    public void SetNext(AbstractAuditer abstractAuditer)
    {
        auditer = abstractAuditer;
    }

    protected void AuditAndInvokNext(ApplyContext context)
    {
        if (context.Hours <= AuditHours)
        {
            context.AuditResult = true;
            context.AuditRemark = "Enjoy you vocation";
            Console.WriteLine($"{this.GetType().Name} {Name} 审批通过了{context.Name} {context.Hours}小时的请假");
        }
        else
        {
            // InvokNext(context);
            if (auditer != null)
            {
                auditer.Audit(context);
            }
        }
        //if (auditer != null)
        //{
        //    auditer.Audit(context);
        //}
    }
}
